export const getMousePosition = (dom: Element, x: number, y: number) => {
  const rect = dom.getBoundingClientRect();
  return [(x - rect.left) / rect.width, (y - rect.top) / rect.height];
};

export const getMouseAbsolutePosition = (dom: Element, x: number, y: number) => {
  const rect = dom.getBoundingClientRect();
  return [x - rect.left, y - rect.top];
};

export const getAbsolutePosition = (dom: Element, x: number, y: number) => {
  const { clientWidth, clientHeight } = dom;
  return [x * clientWidth, y * clientHeight];
};

export const isLeftMouseDown = (event: MouseEvent) => {
  return event.button === 0 && event.buttons === 1;
};

export const isLeftMouseUp = (event: MouseEvent) => {
  return event.button === 0 && event.buttons === 0;
};

export const isMiddleMouseUp = (event: MouseEvent) => {
  return event.button === 1 && event.buttons === 0;
};

export const isMiddleMouseDown = (event: MouseEvent) => {
  return event.button === 1 && event.buttons === 4;
};

export const isRightMouseDown = (event: MouseEvent) => {
  return event.button === 2 && event.buttons === 0;
};

export const isRightMouseUp = (event: MouseEvent) => {
  return event.button === 2 && event.buttons === 0;
};

export const isMouseMove = (event: MouseEvent) => {
  return event.button === -1 && event.buttons === 0;
};
